<?php

namespace app\admin\model;

use app\admin\model\product\Category;
use think\Model;
use traits\model\SoftDelete;

class Goodsselect extends Model
{

//    use SoftDelete;



    // 表名
    protected $name = 'goods';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
//    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'status_text'
    ];
//    public function useSoftDelete($field, $condition = null)
//    {
//        if ($field) {
//            $this->options['soft_delete'] = [$field, $condition ?: 0];
//        }
//        return $this;
//    }

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }


    public function getStatusList()
    {
        return ['up' => __('Status up'), 'hidden' => __('Status hidden'), 'down' => __('Status down')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public  function   category(){

        return $this->hasOne(Category::class,'id','category_ids');
    }




}
